<template>
  <div class="rate">
    <div class="topBox">
      <div class="topBox-left">
        <li><span style="font-size:24px;color:orange">{{ Number(this.rateScores.overall_score).toFixed(1) }}</span></li>
        <li style="font-size:16px">综合评价</li>
        <li style="font-size:10px;color:#999999">高于周边商家{{ (this.rateScores.compare_rating*100).toFixed(1) }}%</li>
      </div>
      <div class="topBox-right">
        <li>服务态度
          <van-rate
            v-model="serviceValue"
            :size="10"
            color="#ffd21e"
            void-icon="star"
            void-color="#eee"
            readonly
          />
          <span style="margin-left:4px;color:red;font-size:14px">{{serviceValue.toFixed(1)}}</span>
        </li>
        <li>菜品评价
          <van-rate
            v-model="foodValue"
            :size="10"
            color="#ffd21e"
            void-icon="star"
            void-color="#eee"
            readonly
          />
          <span style="margin-left:4px;color:red;font-size:14px">{{foodValue.toFixed(1)}}</span>
        </li>
        <li>送达时间<span style="padding-left:6px;font-size:14px;color:gray">{{this.rateScores.deliver_time}} <span style="font-size:10px;color:gray;">分钟</span></span></li>
      </div>
    </div>
    <div class="centerBox">
      <ul>
        <li v-for="(item,index) in rateTags" :key="item.id" :class="{active:active === index}" @click="chooseActive(index)">{{item.name}}({{item.count}})</li>
      </ul>
      <div class="bottomBox" v-for="items in rateList" :key="items.id">
        <van-card
          :title="items.username"
        ><template #price>
            <div v-for="itemImg in rateList.item_ratings" :key="itemImg.id"><img v-lazy="`https://elm.cangdu.org/img/${itemImg.image_hash}`" alt=""></div>
          </template>
         <template #num>
            <div>{{items.rated_at}}</div>
          </template>
          <template #tags>
            <van-rate v-model="items.rating_star" readonly/>
            <span style="padding-left:6px;color:#666666">{{items.time_spent_desc}}</span>
          </template>
          <template #thumb>
            <van-icon name="user-o" />
          </template>
        </van-card>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Rate',
  props: {
    shopId: {
      type: String
    }
  },
  data: () => ({
    rateList: [],
    rateScores: [],
    rateTags: [],
    foodValue: 0,
    serviceValue: 0,
    listValue: 0,
    active: 0
  }),
  created () {
    this.getRateList()
    this.getRateScores()
    this.getRateTags()
  },
  methods: {
    async getRateList () {
      const { data } = await this.$http.getRateList(this.shopId)
      this.rateList = data
      console.log(this.rateList)
    },
    async getRateScores () {
      const { data } = await this.$http.getRateScores(this.shopId)
      this.rateScores = data
      this.foodValue = this.rateScores.food_score
      this.serviceValue = this.rateScores.service_score
    },
    async getRateTags () {
      const { data } = await this.$http.getRateTags(this.shopId)
      this.rateTags = data
    },
    chooseActive (index) {
      this.active = index
    }
  }
}
</script>

<style lang="scss" scoped>
.rate{
  .active{
    background-color: #3190e8 !important;
    color: #fff !important;
  }
  .topBox{
    width: 100%;
    height: 200px;
    margin-top: 10px;
    margin-bottom: 10px;
    box-sizing: border-box;
    background-color: #fff;
    .topBox-left{
      width: 45%;
      height: 100%;
      background-color: #fff;
      float: left;
      padding-top: 40px;
      box-sizing: border-box;
      li {
      text-align: center;
      margin:0 0 4px 0;
      padding: 0;
      font-size: 20px;
      list-style-type: none;
      color: #666666;
      }
    }
    .topBox-right{
      width: 55%;
      height: 100%;
      background-color: #fff;
      float: left;
      box-sizing: border-box;
      padding-top: 40px;
      li {
        margin:0 0 10px 20px;
        padding: 0;
        font-size: 26px;
        list-style-type: none;
        color: #666666;
      }
    }
  }
  .centerBox{
    width: 100%;
    overflow: hidden;
    background-color:#fff;
    padding: 0 10px 0 10px;
    box-sizing: border-box;
    ul{
      width: 100%;
      display: block;
      overflow: hidden;
      padding-top: 12px;
      background-color:#fff;
      padding-left: 5px;
    }
    li{
      padding: 0 10px 0 10px;
      height: 60px;
      float: left;
      font-size: 26px;
      background-color: #ebf5ff;
      margin: 0 6px 6px 6px;
      color: #6d7885;
      border-radius: 10px;
      text-align: center;
      line-height: 60px;
    }
  }
  .bottomBox{
    border-top: #dad8d8 1px solid;
    margin-top: 10px;
    background-color: #fff;
    box-sizing: border-box;
    .van-rate {
      margin-top: 20px;
    }
    .van-card{
      background-color: #fff;
      padding-top: 10px;
    }
    .van-card__title {
      max-height: 30px;
      font-weight: 500;
      line-height: 30px;
      }
    .van-icon-user-o::before {
      content: '\F0D4';
      font-size: 46px;
      text-align: center;
      line-height: 60px;
      margin:10px 0 0 15px;
    }
  }
}
</style>
